package com.hzy.potrace.demo;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.StringUtils;
import com.hzy.potrace.Potrace;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by huzongyao on 18-1-10.
 */

public class AboutActivity extends AppCompatActivity {

    @BindView(R.id.app_version)
    TextView mAppVersion;
    @BindView(R.id.potrace_version)
    TextView mPotraceVersion;
    private ActionBar mActionBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        ButterKnife.bind(this);
        mActionBar = getSupportActionBar();
        if (mActionBar != null) {
            mActionBar.setDisplayHomeAsUpEnabled(true);
        }
        mAppVersion.setText(AppUtils.getAppVersionName());
        mPotraceVersion.setText(Potrace.getVersionString());
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @OnClick({R.id.potrace_official_area, R.id.app_github_area, R.id.my_page_area})
    public void onViewClicked(View view) {
        String url = "";
        switch (view.getId()) {
            case R.id.potrace_official_area:
                url = getString(R.string.potrace_page_url);
                break;
            case R.id.app_github_area:
                url = getString(R.string.github_project_url);
                break;
            case R.id.my_page_area:
                url = getString(R.string.github_me_url);
                break;
        }
        if (!StringUtils.isTrimEmpty(url)) {
            Intent intent = new Intent(this, WebViewActivity.class);
            intent.putExtra(WebViewActivity.INTENT_WEB_VIEW_URL, url);
            startActivity(intent);
        }
    }
}
